from matplotlib import pyplot as plt
import numpy as np

plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False

# Constants.
a = 2.772
c = 2
b = np.sqrt(a**2 - c**2)
r = 1.5

x1 = np.linspace(-a, a, num=100)
oval = np.sqrt(b**2 - b**2/a**2 * x1**2)

x2 = np.linspace(c-r, c+r, num=100)
mars = np.sqrt(r**2 - (x2-c)**2)

x3 = np.linspace(2*c-a, a, num=100)
earth = np.sqrt((a-c)**2 - (x3-c)**2)

plt.title('快速转移示意图')
plt.xticks(np.arange(-3, 4, 1))
plt.yticks(np.arange(-3, 4, 1))
plt.axis('equal')
plt.axis('off')

plt.plot(x1, oval, color='gold', label='快速转移轨道')
plt.plot(x1, -oval, color='gold')
plt.plot(x2, mars, color='red', label='火星公转轨道')
plt.plot(x2, -mars, color='red')
plt.plot(x3, earth, color='lightskyblue', label='地球公转轨道')
plt.plot(x3, -earth, color='lightskyblue')

plt.vlines(1.74, 0, 1.45, linestyles='--', color='black')
plt.plot([1.74, c], [1.45, 0], linestyle='--', color='black')
plt.plot([0, 1.74], [0, 1.45], linestyle='--', color='black')
plt.arrow(-3, 0, 6, 0, head_width=0.1, head_length=0.2, color='black')
plt.arrow(0, -2.5, 0, 5, head_width=0.1, head_length=0.2, color='black')

plt.text(-0.2, -0.2, r'$O$', fontsize=18)
plt.text(1.74, 1.64, r'$D$', fontsize=18)
plt.text(1.64, -0.2, r'$E$', fontsize=18)
plt.text(c-0.1, -0.2, r'$C$', fontsize=18)
plt.text(-0.2, b+0.1, r'$B$', fontsize=18)
plt.text(a, -0.2, r'$A$', fontsize=18)

plt.grid()
plt.legend()
plt.show()
